1. Field of the Invention
The present invention relates to a method, system, and program for controlling access to a sensitive function that is a member of a class.
2. Description of the Related Art
In the prior art JAVA computer programming language, the programmer can specify the level of access other functions have to functions within a another class of objects and functions. (JAVA is a trademark of Sun Microsystems, Inc.). The terms “methods” and “functions” are used herein to refer to programs that perform specific operations. A class is a blueprint or prototype that defines the variables and functions (methods) common to all objects of a certain kind. In the JAVA programming language, a group of classes can be grouped and associated resources can be organized into a package, which makes classes easier to manage, helps avoid naming conflicts, and control access. A package is a collection of related classes and interfaces that provides access protection and namespace management.
Classes can protect their member methods and functions from access by other objects. The programmer would add access specifiers in the class declaration to protect both a class's variables and its methods. The JAVA language supports four distinct access levels for member methods: private, protected, public, and, if left unspecified, package. A class in all situations has access to its own members.
The most restrictive access level is private. A private member is accessible only to other members in the class in which it is defined. A member, i.e., method or data object, can only be used by other members of the same class. This includes variables that contain information that if accessed by an outsider could put the object in an inconsistent state, or methods that, if invoked by an outsider, could jeopardize the state of the object or the program in which it's running. A member of a class declared as protected can be accessed by members of the same class, subclasses, and all classes in the same package. A member of a class declared as public can by accessed by any class in any package. The package access level allows classes in the same package to access any members within classes grouped in the package. This level of access assumes that classes in the same package are trusted friends. The package access level is the default access level if another access level is not specified.
In the prior art JAVA programming language, one way to limit access to a sensitive function is to declare the sensitive function public and not publish any information about the sensitive function. However, this technique will not prevent hackers from learning about the sensitive function and from maliciously utilizing the sensitive object. Another current solution is to copy the sensitive function to all packages that need to use the function. However, this approach often leads to complications because functions may call further functions, and copying one function in a chain to the packages will not necessarily allow the external calling function in another package access to the nested functions. Access can also be limited by declaring the sensitive function protected so that only functions in a class that inherit the properties of the class including the sensitive function can access the sensitive function. However, this technique requires that inheritance be declared, which can be problematic if the developer only wants to provide access to one sensitive function in a class and not all functions in the class. Thus, there is a need in the JAVA programming language to provide greater flexibility in controlling access to sensitive functions than is currently available with the current four access level options, i.e., public, private, protected, and package.
The prior art C++ programming language does not provide the concept of a package of classes. C++ allows class members to be declared as private so only other members of the same class as the private class member can access the class. A C++ class member declared as protected can only can only be used inside the class in which it is declared or in any derived or inheriting classes. The prior art C++ programming language also provides the concept of “friends”, which allows members of external classes to have access to a private member of another class. The friend declaration appears in the class that contains the private member, and declares an external function in another class which has access. C++ applies the friends definition during compilation. If, during compilation, a member in one class attempts to access a member in another class, then the friends definition will be examined. If the calling member in the external class is not declared as a friend, then the compilation will fail.
Although C++ provides a mechanism to limit access to specified members of another class, the C++ friends technique is not flexible in that the binding of members of one class to members of another class occurs at compilation time and cannot be altered during runtime.
Thus, there is a need in the art to provide more freedom to control access to members of a class, e.g., methods and function, in object oriented programming languages such as JAVA and C++.